<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="/css/style.css?version=<?php echo $version?>" rel="stylesheet" />
<link type="text/css" href="/css/index.css?version=<?php echo $version?>" rel="stylesheet" />
<link type="text/css" href="/css/patch_home.css?version=<?php echo $version?>" rel="stylesheet" />
<script language="javascript" src="/js/jquery-1.11.1.min.js?version=<?php echo $version?>"></script>
<title>管理平台首页</title>
</head>
<body>
<style>
table {font-size:12px;border-collapse:collapse}
table td{border:1px solid #CCCCCC;height:30px;padding:5px}
</style>
</head>
<body>
<div class="mG_main">
	<!-- main -->
	<div class="mG_module">
		<div class="user_list">
			<div class="user_list">
				<form name="upform" action="" method="post">
					<input type="hidden" name="id" value="<?php echo isset($id) ? $id : ''?>" />
					<input type="hidden" name="material_id" id="material_id" value="<?php echo isset($autoreply['material_id']) ? $autoreply['material_id'] : ''?>" />
					<table cellspacing="0" cellpadding="0" >
						<tr><td>规则分类</td><td>
							<select name="type" id="type"><option value="0">未分类</option><?php foreach ($all_type as $_key => $_type){if ($_key > 0){$is_selected = (isset($autoreply['type']) && $_key == $autoreply['type']) ? 'selected' : '';echo "<option value=\"{$_key}\" {$is_selected}>{$_type}</option>";}}?><option value="add">添加分类</option></select>
						</td></tr>
						<tr><td width="80">规则名</td><td width="350">
							<input type="text" name="rule_name" id="rule_name" value="<?php echo isset($autoreply['rule_name']) ? $autoreply['rule_name'] : ''?>" size="50"/>
						</td></tr>
						<tr><td>关键字</td><td>
							<span id="keywords"><?php if (!empty($autoreply['keyword'])){foreach ($autoreply['keyword'] as $_key => $_keyword){echo '<br/><span id="keyword_' . $_key . '"><input type="text" name="keyword[]" class="keyword" value="' . $_keyword . '" /><a href="javascript: void(0)" class="del_keyword" num="' . $_key . '"> <img alt="新加" src="/images/iconfont-jian.png" width="15px"></a></span>';}}?></span><br/><a href="javascript:void(0)" id="add_keyword"><img alt="新加" src="/images/iconfont-jia.png" width="15px"></a>
						</td></tr>
						<tr><td>回复类型</td><td>
							<select name="material_type" id="material_type"><?php foreach ($all_material_type as $_key => $_type){if ($_key > 0){$is_selected = (isset($autoreply['material_type']) && $_key == $autoreply['material_type']) ? 'selected' : '';echo "<option value=\"{$_key}\" {$is_selected}>{$_type}</option>";}}?></select>
						</td></tr>
						<tr><td>回复内容</td><td>
							<?php $material_type = isset($autoreply['material_type']) ? $autoreply['material_type'] : 1;
							if (!empty($material_list)){
								foreach ($material_list as $_mtype => $_material_type){
									echo '<div id="material_type_'.$_mtype.'" ' . (($_mtype != $material_type) ? 'style="display:none;"' : '') . '>';
									foreach ($_material_type as $_material){
										$is_checked = (isset($autoreply['material_id']) && in_array($_material['id'], $autoreply['material_id_arr'])) ? 'checked' : '';
										echo '<p><label><input type="checkbox" '.$is_checked.' name="material_id_checked" mid="'.$_material['id'].'" class="material_id_check" /> '.$_material['title'].'</label></p>';
									}
									echo '</div>';
								}
							}?>
							<div id="material_type_6" <?php echo ($material_type != 6) ? 'style="display:none;"' : ''?>>
								<textarea name="content" id="content" rows="7" cols="70"><?php echo isset($autoreply['content']) ? $autoreply['content'] : ''?></textarea>
							</div>
						</td></tr>
					</table>
					<div style="margin-top:10px">
						<input type="submit" value=" 确 定 " />&nbsp;&nbsp;
						<input type="button" onclick="javascript: window.history.back()" value=" 取 消 " />
					</div>
				</form>
			</div>
		</div>
	</div>
	<!-- /main-->
	<div class="clearit"></div>
</div>

<script type="text/javascript">
function del_keyword(){
	$(".del_keyword").click(function(){
		if ($("#keywords").find("input").length < 2){
			return true;
		}
		var _num = $(this).attr("num");
		$("#keyword_"+_num).remove();
	});
}

$(document).ready(function(){
	$("#type").change(function(){
		if ($(this).val() == 'add'){
			window.location.href = '/autoreply/typeedit/';
		}
	});
	
	$("#add_keyword").click(function(){
		var num = $("#keywords").find("input").length;
		$("#keywords").append('<span id="keyword_' + num + '"><br/><input type="text" name="keyword[]" class="keyword" value="" /><a href="javascript: void(0)" class="del_keyword" num="' + num + '"> <img alt="新加" src="/images/iconfont-jian.png" width="15px"></a></span>');
		del_keyword();
	});
	del_keyword();

	$("#material_type").change(function(){
		$("div[id^='material_type_']").each(function(){
			$(this).hide();
		});
		$("#material_type_"+$(this).val()).show();

		$(".material_id_check:checked").each(function(){
			$(this).attr("checked", false);
		});
		$("#material_id").val('');
	});

	$(".material_id_check").change(function(){
		var material_ids = '';
		var material_arr = new Array();
		$(".material_id_check:checked").each(function(){
			//$(this).attr("checked", false);
			material_arr[material_arr.length] = $(this).attr('mid');
		});
		$("#material_id").val(material_arr.join(","));
	});
});
</script>

</body>
</html>
